﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using CakeLibrary;

namespace Medianamik.UI.Mediasend.Logic
{
    public class MediasendList
    {
        public int ID { get; private set; }
        public string Name { get; private set; }
        public ListStatus Status { get; private set; }
        public CultureInfo Language { get; private set; }
        public DateTime CreatedOn { get; private set; }
        public string SenderName { get; private set; }
        public string SenderEmail { get; private set; }
        public int ContactCount { get; set; }
        public IEnumerable<MediasendSubList> SubList { get; set; }

        internal MediasendList(int id, string name, ListStatus status, CultureInfo language, DateTime createdOn, string senderName, string senderEmail)
        {
            ID = id;
            Name = name;
            Status = status;
            Language = language;
            CreatedOn = createdOn;
            SenderName = senderName;
            SenderEmail = senderEmail;
            SubList = new List<MediasendSubList>();
        }

        internal static MediasendList MakeList(Dictionary<string, object> record)
        {
            var list = new MediasendList(int.Parse(record["id"].ToString()),
                                     record["name"].ToString(),
                                     record["status"].ToString() == "active"
                                     ? ListStatus.Active
                                     : ListStatus.Archived,
                                     new CultureInfo(record["language"].ToString().Replace('_', '-')),
                                     DateTime.Parse(record["created_on"].ToString()),
                                     record["sender_name"].ToString(),
                                     record["sender_email"].ToString());            
            return list;
        }
    }

    public enum ListStatus
    {
        Active,
        Archived
    }
}
